/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package load.logic;

import core.InPort;
import core.OutPort;
import core.DispatcherPort;
import core.StdNode;
import core.TriggerPort;

/**
 * Node which behaves like conditional expression "condition ? arg1 : arg2".
 * The value of 'res' is equal to that of 'arg1' if 'condition' is true, 
 * otherwise it is equal to 'arg2'.
 * 
 * @author Wijnand
 */
public class IntSelect extends StdNode {
	private DispatcherPort resChanged = new DispatcherPort();
	private TriggerPort argChanged = new TriggerPort() {
		@Override
		public void callInternal() {
			resChanged.callTargets();
		}
	};
	private InPort arg1 = new InPort(Integer.class, argChanged);
	private InPort arg2 = new InPort(Integer.class, argChanged);
	private InPort condition = new InPort(Boolean.class, argChanged);
	private OutPort res = new OutPort(Integer.class, resChanged)
	{
		@Override
		public Object getValueInternal() {
                        Object result = null;
			if (((Boolean)condition.getValue()).booleanValue())
				result =  (Integer)arg1.getValue();
			else
				result =  (Integer)arg2.getValue();
                        return result;
		}
	};
	
	public IntSelect() {
		autoPutPorts();
	}
}
